
<!DOCTYPE html>
<!--[if IEMobile 7 ]><html class="no-js iem7"><![endif]-->
<!--[if lt IE 9]><html class="no-js lte-ie8"><![endif]-->
<!--[if (gt IE 8)|(gt IEMobile 7)|!(IEMobile)|!(IE)]><!--><html class="no-js" lang="en"><!--<![endif]-->

<head>


<meta charset="utf-8">
<meta http-equiv="cleartype" content="on">

<title>Unsupported Major Minor Version 51 - Sam小龙</title>
<meta name="author" content="xiaolong.yuanxl">




<meta name="description" content="jdk不能向上兼容">

<meta name="keywords" content="java ">


<!-- http://t.co/dKP3o1e -->
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- Twitter Cards -->


<!-- Open Graph -->
<meta property="og:local" content="en_US">
<meta property="og:type" content="article">
<meta property="og:url" content="http://yuanxiaolong.github.io/blog/2014/08/11/unsupported-major-minor-version-51">
<meta property="og:title" content="Unsupported major minor version 51">
<meta property="og:description" content="jdk不能向上兼容">

  <meta property="og:image" content="">

<meta property="og:site_name" content="Sam小龙">

<link rel="canonical" href="http://yuanxiaolong.github.io/blog/2014/08/11/unsupported-major-minor-version-51">
<link href="/favicon.png" rel="icon">
<link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
<!-- <link href="//netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet"> -->
<link href="/stylesheets/font-awesome.min.css" rel="stylesheet">
<link href="/atom.xml" rel="alternate" title="Sam小龙" type="application/atom+xml">

<!-- the flow button on left -->
<script src="/javascripts/vendor/modernizr-2.6.2.custom.min.js"></script>


  <style type="text/css">body {background-image:url(/images/bg.jpg);background-size:cover;}</style>

<!-- 
  

  
    
  

  <style type="text/css">body {background-image:url(
      /images/
    
      bg.jpg
    
  
    );}</style>
 -->

<!--Fonts from Google"s Web font directory at http://google.com/webfonts
<link href="//fonts.googleapis.com/css?family=PT+Serif:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
<link href="//fonts.googleapis.com/css?family=PT+Sans:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
-->


</head>

<body id="post" >

<!--[if lt IE 9]><div class="upgrade"><strong><a href="http://whatbrowser.org/">Your browser is quite old!</strong> Why not upgrade to a different browser to better enjoy this site?</a></div><![endif]-->
<nav id="dl-menu" class="dl-menuwrapper" role="navigation">
	<button class="dl-trigger">Open Menu</button>
	<ul class="dl-menu">
		<li><a href="/">主页</a></li>

		<li>
			<a href="#">内容</a>
			<ul class="dl-submenu">
				<li><a href="/posts/">文章列表</a></li>
				<li><a href="/categories/">分类列表</a></li>
			</ul>
		</li>

		<li>
			<a href="#">关于</a>
			<ul class="dl-submenu">
				<li>
					<img src="/images/avatar.png" alt="xiaolong.yuanxl photo" class="author-photo">
					<h4>xiaolong.yuanxl</h4>
					<p></p>
				</li>
				<li><a href="/about">关于我</a></li>
				<li>
					<a href="mailto:232351936@qq.com"><i class="fa fa-envelope"></i> Email</a>
				</li>
				
				
				<li>
					<a href="http://github.com/yuanxiaolong"><i class="fa fa-github"></i> GitHub</a>
				</li>
			</ul><!-- /.dl-submenu -->
		</li>

		
	</ul><!-- /.dl-menu -->
</nav><!-- /.dl-menuwrapper -->




<div id="main" role="main" >
  <article class="hentry">
    <header class="header-title">
      <div class="header-title-wrap">
        
          <h1 class="entry-title"><a href="/blog/2014/08/11/unsupported-major-minor-version-51/" rel="bookmark" title="Unsupported major minor version 51">Unsupported major minor version 51</a></h1>
        
        <h2>August 11, 2014</h2>
      </div><!-- /.header-title-wrap -->
    </header>
    <div class="entry-content">
      <p>今天碰见一个普通的问题，期初以为是环境问题，后来才发现是maven依赖的问题。</p>

<!--more-->
<p>把过程分享给大家，解决问题很简单，定位问题不容易啊，因为方向考虑错了……</p>

<hr />

<h2 id="section">背景</h2>

<ol>
  <li>在centos上运行一个jetty启动的服务jar包。</li>
  <li>本机<font color="green"> windows，jdk1.7，maven3.1.1，eclipse </font></li>
</ol>

<p>本地写的jar包放到linux机上报错。</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
<span class="line-number">2</span>
<span class="line-number">3</span>
<span class="line-number">4</span>
<span class="line-number">5</span>
<span class="line-number">6</span>
<span class="line-number">7</span>
<span class="line-number">8</span>
<span class="line-number">9</span>
<span class="line-number">10</span>
<span class="line-number">11</span>
<span class="line-number">12</span>
<span class="line-number">13</span>
<span class="line-number">14</span>
</pre></td><td class="code"><pre><code class="java"><span class="line"> <span class="n">java</span><span class="o">.</span><span class="na">lang</span><span class="o">.</span><span class="na">UnsupportedClassVersionError</span><span class="o">:</span> <span class="n">javax</span><span class="o">/</span><span class="n">servlet</span><span class="o">/</span><span class="n">Servlet</span> <span class="o">:</span> <span class="n">Unsupported</span> <span class="n">major</span><span class="o">.</span><span class="na">minor</span> <span class="n">version</span> <span class="mf">51.0</span>
</span><span class="line">	<span class="n">at</span> <span class="n">java</span><span class="o">.</span><span class="na">lang</span><span class="o">.</span><span class="na">ClassLoader</span><span class="o">.</span><span class="na">defineClass1</span><span class="o">(</span><span class="n">Native</span> <span class="n">Method</span><span class="o">)</span>
</span><span class="line">	<span class="n">at</span> <span class="n">java</span><span class="o">.</span><span class="na">lang</span><span class="o">.</span><span class="na">ClassLoader</span><span class="o">.</span><span class="na">defineClassCond</span><span class="o">(</span><span class="n">ClassLoader</span><span class="o">.</span><span class="na">java</span><span class="o">:</span><span class="mi">631</span><span class="o">)</span>
</span><span class="line">	<span class="n">at</span> <span class="n">java</span><span class="o">.</span><span class="na">lang</span><span class="o">.</span><span class="na">ClassLoader</span><span class="o">.</span><span class="na">defineClass</span><span class="o">(</span><span class="n">ClassLoader</span><span class="o">.</span><span class="na">java</span><span class="o">:</span><span class="mi">615</span><span class="o">)</span>
</span><span class="line">	<span class="n">at</span> <span class="n">java</span><span class="o">.</span><span class="na">security</span><span class="o">.</span><span class="na">SecureClassLoader</span><span class="o">.</span><span class="na">defineClass</span><span class="o">(</span><span class="n">SecureClassLoader</span><span class="o">.</span><span class="na">java</span><span class="o">:</span><span class="mi">141</span><span class="o">)</span>
</span><span class="line">	<span class="n">at</span> <span class="n">java</span><span class="o">.</span><span class="na">net</span><span class="o">.</span><span class="na">URLClassLoader</span><span class="o">.</span><span class="na">defineClass</span><span class="o">(</span><span class="n">URLClassLoader</span><span class="o">.</span><span class="na">java</span><span class="o">:</span><span class="mi">283</span><span class="o">)</span>
</span><span class="line">	<span class="n">at</span> <span class="n">java</span><span class="o">.</span><span class="na">net</span><span class="o">.</span><span class="na">URLClassLoader</span><span class="o">.</span><span class="na">access</span><span class="n">$000</span><span class="o">(</span><span class="n">URLClassLoader</span><span class="o">.</span><span class="na">java</span><span class="o">:</span><span class="mi">58</span><span class="o">)</span>
</span><span class="line">	<span class="n">at</span> <span class="n">java</span><span class="o">.</span><span class="na">net</span><span class="o">.</span><span class="na">URLClassLoader</span><span class="n">$1</span><span class="o">.</span><span class="na">run</span><span class="o">(</span><span class="n">URLClassLoader</span><span class="o">.</span><span class="na">java</span><span class="o">:</span><span class="mi">197</span><span class="o">)</span>
</span><span class="line">	<span class="n">at</span> <span class="n">java</span><span class="o">.</span><span class="na">security</span><span class="o">.</span><span class="na">AccessController</span><span class="o">.</span><span class="na">doPrivileged</span><span class="o">(</span><span class="n">Native</span> <span class="n">Method</span><span class="o">)</span>
</span><span class="line">	<span class="n">at</span> <span class="n">java</span><span class="o">.</span><span class="na">net</span><span class="o">.</span><span class="na">URLClassLoader</span><span class="o">.</span><span class="na">findClass</span><span class="o">(</span><span class="n">URLClassLoader</span><span class="o">.</span><span class="na">java</span><span class="o">:</span><span class="mi">190</span><span class="o">)</span>
</span><span class="line">	<span class="n">at</span> <span class="n">java</span><span class="o">.</span><span class="na">lang</span><span class="o">.</span><span class="na">ClassLoader</span><span class="o">.</span><span class="na">loadClass</span><span class="o">(</span><span class="n">ClassLoader</span><span class="o">.</span><span class="na">java</span><span class="o">:</span><span class="mi">306</span><span class="o">)</span>
</span><span class="line">	<span class="n">at</span> <span class="n">sun</span><span class="o">.</span><span class="na">misc</span><span class="o">.</span><span class="na">Launcher</span><span class="n">$AppClassLoader</span><span class="o">.</span><span class="na">loadClass</span><span class="o">(</span><span class="n">Launcher</span><span class="o">.</span><span class="na">java</span><span class="o">:</span><span class="mi">301</span><span class="o">)</span>
</span><span class="line">	<span class="n">at</span> <span class="n">java</span><span class="o">.</span><span class="na">lang</span><span class="o">.</span><span class="na">ClassLoader</span><span class="o">.</span><span class="na">loadClass</span><span class="o">(</span><span class="n">ClassLoader</span><span class="o">.</span><span class="na">java</span><span class="o">:</span><span class="mi">247</span><span class="o">)</span>
</span><span class="line"><span class="n">Exception</span> <span class="n">in</span> <span class="n">thread</span> <span class="s">&quot;main&quot;</span>
</span></code></pre></td></tr></table></div></figure></notextile></div>

<hr />

<h2 id="section-1">分析过程</h2>

<p>1.先百度google了一下，本质是高版本jdk编写的class文件在低版本jdk上不能运行。于是到linux上看了一下</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
<span class="line-number">2</span>
<span class="line-number">3</span>
<span class="line-number">4</span>
</pre></td><td class="code"><pre><code class="bash"><span class="line"><span class="o">[</span>hadoop@wh-9-103 ~<span class="o">]</span><span class="nv">$ </span>java -version
</span><span class="line">java version <span class="s2">&quot;1.6.0_20&quot;</span>
</span><span class="line">Java<span class="o">(</span>TM<span class="o">)</span> SE Runtime Environment <span class="o">(</span>build 1.6.0_20-b02<span class="o">)</span>
</span><span class="line">Java HotSpot<span class="o">(</span>TM<span class="o">)</span> 64-Bit Server VM <span class="o">(</span>build 16.3-b01, mixed mode<span class="o">)</span>
</span></code></pre></td></tr></table></div></figure></notextile></div>

<p>果然 1.7的jdk程序不能在1.6上运行。。。。</p>

<p>2.卸载jdk1.7，重装jdk1.6，本机运行。同样报错如上，很奇怪，本机是1.6的jdk。
而之前1.7的jdk本机运行良好，怀疑是不是运行程序时，找之前的jdk1.7？</p>

<p>百度后，有人说windows注册表里还是1.7jdk，因此出错。重装3遍无果….</p>

<p>3.运行时候加上 vm参数 <font color="#0ea373"> -verbose </font>，运行main，发现还是一样，但可以看出，已经是加载jdk1.6的了。</p>

<p>4.从异常栈出发，<font color="#0c22a1"> javax/servlet/Servlet </font>肯定是这里的问题，maven看一下依赖。跟这个类有关的竟然有2个jar</p>

<ul>
  <li>javax.servlet-api:3.1.0</li>
  <li>servlet-api:2.5</li>
</ul>

<p><img src="/images/java/20140811/mvn-dep.png" alt="mvn-dep" /></p>

<p>一般是2.5的那个，而3.1的那个是从哪里依赖过来的？</p>

<p>原来是jetty-server，高版本的它依赖了最后面用jdk1.7编译的jar。因此换个低版本的jetty-server就好了。</p>


      <!-- add copyright for each post -->
      <div style="margin-top:20px;">
        <font color="gray" size="3">
          原文地址，转载请注明出处:<br/>
          <a href="http://blog.yuanxiaolong.cn/blog/2014/08/11/unsupported-major-minor-version-51/">http://blog.yuanxiaolong.cn/blog/2014/08/11/unsupported-major-minor-version-51/</a>
        </font>
      </div>
      <footer class="entry-meta">
        <span class="entry-tags"><a href="/categories/#java" title="Pages tagged java" class="tag">java</a></span>
        <span><a href="/blog/2014/08/11/unsupported-major-minor-version-51/" rel="bookmark" title="Unsupported major minor version 51">Unsupported major minor version 51</a> was published on <span class="entry-date date published updated"><time datetime="2014-08-11T22:05:35+08:00">August 11, 2014</time></span></span>
        
        <span class="author vcard"><span class="fn"><a href="" title="About xiaolong.yuanxl">xiaolong.yuanxl</a></span></span>
        <div class="social-share">
          <div class="socialcount socialcount-small inline-list">
            <!-- <li class="facebook"><a href="https://www.facebook.com/sharer/sharer.php?u=/blog/2014/08/11/unsupported-major-minor-version-51/" title="Share on Facebook"><span class="count"><i class="fa fa-facebook-square"></i> Like</span></a></li>
            <li class="twitter"><a href="https://twitter.com/intent/tweet?text=/blog/2014/08/11/unsupported-major-minor-version-51/" title="Share on Twitter"><span class="count"><i class="fa fa-twitter-square"></i> Tweet</span></a></li>
            <li class="googleplus"><a href="https://plus.google.com/share?url=/blog/2014/08/11/unsupported-major-minor-version-51/" title="Share on Google Plus"><span class="count"><i class="fa fa-google-plus-square"></i> +1</span></a></li> -->
            <!-- 多说评论框 start -->
          	<div class="ds-thread" data-thread-key="/blog/2014/08/11/unsupported-major-minor-version-51/" data-title="Unsupported major minor version 51" data-url="http://blog.yuanxiaolong.cn/blog/2014/08/11/unsupported-major-minor-version-51/"></div>
            <!-- 多说评论框 end -->
            <!-- 多说公共JS代码 start (一个网页只需插入一次) -->
            <script type="text/javascript">
            var duoshuoQuery = {short_name:"yuanxiaolong"};
            	(function() {
            		var ds = document.createElement('script');
            		ds.type = 'text/javascript';ds.async = true;
            		ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
            		ds.charset = 'UTF-8';
            		(document.getElementsByTagName('head')[0]
            		 || document.getElementsByTagName('body')[0]).appendChild(ds);
            	})();
            	</script>
            <!-- 多说公共JS代码 end -->
        </div>
        </div><!-- /.social-share -->
      </footer>

    </div><!-- /.entry-content -->
    
      <div class="read-more">
        
          <div class="read-more-header">
            <a href="/blog/2014/09/07/install-nfs-and-share-file/" class="btn">Read More</a>
          </div><!-- /.read-more-header -->
          <div class="read-more-content">
            <h3><a href="/blog/2014/09/07/install-nfs-and-share-file/" title="install nfs and shshare file">install nfs and shshare file</a></h3>
            <p>安装nfs服务器，用于共享配置 <a href="/blog/2014/09/07/install-nfs-and-share-file/"> Continue reading</a></p>
          </div><!-- /.read-more-content -->
        
        <div class="read-more-list">
          
            <div class="list-item">
              <h4><a href="/blog/2014/09/07/install-dns-server-bind/" title="install dns server bind">install dns server bind</a></h4>
              <span>Published on September 07, 2014</span>
            </div><!-- /.list-item -->
          
            <div class="list-item">
              <h4><a href="/blog/2014/08/31/analysis-hadoop-load-configuration/" title="analysis hadoop load configuration">analysis hadoop load configuration</a></h4>
              <span>Published on August 31, 2014</span>
            </div><!-- /.list-item -->
          
        </div><!-- /.read-more-list -->
      </div><!-- /.read-more -->
    
    
  </article>
</div><!-- /#main -->

<div class="footer-wrapper">
  <footer role="contentinfo">
    <span>&copy; 2014 xiaolong.yuanxl. Powered by <a href="http://octopress.org">Octopress</a> using the <a href="https://github.com/Z1MM32M4N/hpstr-theme/">HPSTR Theme for Octopress</a>.</span>

  </footer>
</div><!-- /.footer-wrapper -->



<script src="http://cdn.staticfile.org/jquery/1.9.1/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="/javascripts/vendor/jquery-1.9.1.min.js"><\/script>')</script>
<!--
<script src="/javascripts/octopress.js" type="text/javascript"></script>
-->
<script src="/javascripts/scripts.min.js"></script>
<!-- 
 -->
<script type="text/javascript" src="http://tajs.qq.com/stats?sId=35560703" charset="UTF-8"></script>






</body>
</html>
